<template>
    <div class="form1 pb100">
        <sc-title>初三上学期考试成绩 (必填)</sc-title>
        <van-form ref="van-form" scroll-to-error :show-error="false">
            <!--语文-->
            <van-field
                v-model="subForm.testScores.language"
                name="language"
                required
                type="number"
                input-align="right"
                error-message-align="right"
                label="语文"
                placeholder="请填写语文成绩"
                :rules="[{ required: true, message: '请填写语文成绩' }]"
            />
            <!--数学-->
            <van-field
                v-model="subForm.testScores.math"
                name="math"
                required
                type="number"
                input-align="right"
                error-message-align="right"
                label="数学"
                placeholder="请填写数学成绩"
                :rules="[{ required: true, message: '请填写数学成绩' }]"
            />
            <!--英语-->
            <van-field
                v-model="subForm.testScores.english"
                name="english"
                required
                type="number"
                input-align="right"
                error-message-align="right"
                label="英语"
                placeholder="请填写英语成绩"
                :rules="[{ required: true, message: '请填写英语成绩' }]"
            />

            <!--物理-->
            <van-field
                v-model="subForm.testScores.physics"
                name="physics"
                required
                type="number"
                input-align="right"
                error-message-align="right"
                label="物理"
                placeholder="请填写物理成绩"
                :rules="[{ required: true, message: '请填写物理成绩' }]"
            />

            <!--化学-->
            <van-field
                v-model="subForm.testScores.chemical"
                name="chemical"
                required
                type="number"
                input-align="right"
                error-message-align="right"
                label="化学"
                placeholder="请填写化学成绩"
                :rules="[{ required: true, message: '请填写化学成绩' }]"
            />

            <!--道德与法治-->
            <van-field
                v-model="subForm.testScores.politics"
                name="politics"
                required
                type="number"
                input-align="right"
                error-message-align="right"
                label="道德与法治"
                placeholder="请填写道德与法治成绩"
                :rules="[{ required: true, message: '请填写道德与法治成绩' }]"
            />

            <!--历史-->
            <van-field
                v-model="subForm.testScores.history"
                name="history"
                required
                type="number"
                input-align="right"
                error-message-align="right"
                label="历史"
                placeholder="请填写历史"
                :rules="[{ required: true, message: '请填写历史' }]"
            />

            <!--总分-->
            <van-field
                v-model="subForm.testScores.totalScore"
                name="totalScore"
                required
                type="number"
                input-align="right"
                error-message-align="right"
                label="总分"
                placeholder="请填写总分"
                :rules="[{ required: true, message: '请填写总分' }]"
            />

        </van-form>

        <div class="fixed-btn" v-if="!isFous">
            <sc-button type="stop" width="150px" @click="$emit('changeStep',1)">上一步</sc-button>
            <div class="ml10">
                <sc-button width="190px" @click="onSubmit">保存,下一步</sc-button>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name: "form3",
    data() {
        return {
            popup: {
                applyProject: false,//报考类型
                born: false,//出生年月
            },
            subForm: {
                testScores: {
                    "chemical": "",//化学
                    "english": "",//英语
                    "history": "",//历史
                    "language": "",//语文
                    "math": "",//数学
                    "physics": "",//物理
                    "politics": "",//道德与法治
                    "totalScore": ""//	总分
                }
            },

        }
    },
    created() {
        if (this.$ls.get('subForm3')) this.subForm = this.$ls.get('subForm3')
    },
    destroyed() {
        this.$ls.set('subForm3', this.subForm)
    },
    methods: {
        onSubmit() {
            this.$refs['van-form'].validate().then(() => {
                // 验证通过
                this.$ls.set('subForm3', this.subForm)
                this.$toast.success('保存成功！\n下一步')
                setTimeout(() => {
                    this.$emit('changeStep',3)
                },1000)
            }).catch(() => {
                //验证失败
                this.$toast.fail('必填项\n未填写')
            })
        },
        reset() {
            this.subForm = {
                testScores: {
                    "chemical": "",//化学
                    "english": "",//英语
                    "history": "",//历史
                    "language": "",//语文
                    "math": "",//数学
                    "physics": "",//物理
                    "politics": "",//道德与法治
                    "totalScore": ""//	总分
                }
            }
            this.$toast.success('重置成功！')
            this.$ls.set('subForm3', this.subForm)
        },

    },
}
</script>
<style lang='scss' scoped>
.form1 {
    .change-img {
        background: #F7F8FA;
        position: relative;
        width: calc(295px / 3);
        height: calc(413px / 3);

        img {
            width: calc(295px / 3);
        }

        .saasIcon {
            font-size: 30px;
            color: #ccc;
        }
    }
}
</style>
